package com.ruoyi.web.controller.party;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.party.domain.PartyPerson;
import com.ruoyi.party.service.IPartyPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户数据Controller
 * 
 * @author ruoyi
 * @date 2024-07-07
 */
@RestController
@RequestMapping("/party/person")
public class PartyPersonController extends BaseController
{
    @Autowired
    private IPartyPersonService partyPersonService;

    /**
     * 查询用户数据列表
     */
    @Anonymous
//    @PreAuthorize("@ss.hasPermi('party:person:list')")
    @GetMapping("/list")
    public TableDataInfo list(PartyPerson partyPerson)
    {
        startPage();
        List<PartyPerson> list = partyPersonService.selectPartyPersonList(partyPerson);
        return getDataTable(list);
    }

    /**
     * 导出用户数据列表
     */
    @PreAuthorize("@ss.hasPermi('party:person:export')")
    @Log(title = "用户数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartyPerson partyPerson)
    {
        List<PartyPerson> list = partyPersonService.selectPartyPersonList(partyPerson);
        ExcelUtil<PartyPerson> util = new ExcelUtil<PartyPerson>(PartyPerson.class);
        util.exportExcel(response, list, "用户数据数据");
    }

    /**
     * 获取用户数据详细信息
     */
    @Anonymous
//    @PreAuthorize("@ss.hasPermi('party:person:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(partyPersonService.selectPartyPersonById(id));
    }

    /**
     * 新增用户数据
     */
    @PreAuthorize("@ss.hasPermi('party:person:add')")
    @Log(title = "用户数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartyPerson partyPerson)
    {
        return toAjax(partyPersonService.insertPartyPerson(partyPerson));
    }

    /**
     * 修改用户数据
     */
    @PreAuthorize("@ss.hasPermi('party:person:edit')")
    @Log(title = "用户数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartyPerson partyPerson)
    {
        return toAjax(partyPersonService.updatePartyPerson(partyPerson));
    }

    /**
     * 删除用户数据
     */
    @PreAuthorize("@ss.hasPermi('party:person:remove')")
    @Log(title = "用户数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(partyPersonService.deletePartyPersonByIds(ids));
    }
}
